home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga CD-ROM Collection
/
Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso
/
auge4000
/
46
/
lib
/
time
/
localtime.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-20
|
1KB
|
50 lines
/*
* time/localtime.c
*/
#include <time.h>
static char dim[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
struct tm *
localtime(tp)
const time_t *tp;
{
static struct tm Tm;
time_t t = *tp; /* seconds since 1-jan-78 */
long days, years;
short leap, month;
days = t / 86400 + 731; /* days since 1976 (lyp yr)*/
Tm.tm_wday = (days + 4) % 7;
Tm.tm_sec = t % 60;
Tm.tm_min = t / 60 % 60;
Tm.tm_hour= t / (60*60) % 24;
years = days / (366+365*3); /* #quad yrs */
days -= years * (366+365*3); /* days remaining */
/* 0 = jan 1 */
leap = (days <= 365); /* 0-365, is a leap yr */
years = 1976 + 4 * years; /* base yr */
if (leap == 0) { /* days >= 366 */
days -= 366; /* add a year */
++years;
years += days / 365; /* non-lyrs left */
days %= 365; /* 0-364 */
}
Tm.tm_yday = days;
Tm.tm_year = years - 1900;
Tm.tm_isdst= 0; /* ???? XXX */
for (month = 0; (month==1) ? (days >= 28 + leap) : (days >= dim[month]); ++month)
days -= (month==1) ? (28 + leap) : dim[month];
Tm.tm_mon = month;
Tm.tm_mday = days + 1;
return(&Tm);
}